//
//  MainViewController.m
//  MELive
//
//  Created by 曹曹 on 2016/10/18.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "MainViewController.h"
#import "GB_HotViewController.h"
#import "LiveViewController.h"
#import "HomePageViewController.h"

@interface MainViewController ()<UITabBarControllerDelegate>

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    [self creatTabBar];
}
- (void)creatTabBar {
    GB_HotViewController *hotVC = [[GB_HotViewController alloc] initWithNibName:@"GB_HotViewController" bundle:[NSBundle mainBundle]];
    LiveViewController * liveVC = [[LiveViewController alloc] init];
    HomePageViewController * discoverVC = [[HomePageViewController alloc] init];
    [self addChildVC:hotVC Title:@"" Image:@"theme0_main_tabbar_follow_normal80px" SeleImage:@"theme0_main_tabbar_follow_select80px"];
    [self addChildVC:liveVC Title:@"" Image:@"find_topic_openlive_btn" SeleImage:@"find_topic_openlive_btn"];
    [self addChildVC:discoverVC Title:@"" Image:@"theme0_main_tabbar_find_normal80px" SeleImage:@"theme0_main_tabbar_find_select80px"];
}
-(void)addChildVC:(UIViewController *)childVC
            Title:(NSString *)title
            Image:(NSString *)image
        SeleImage:(NSString *)seleImage{
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childVC];
    childVC.title = title;
    childVC.tabBarItem.image = [UIImage imageNamed:image];
    childVC.tabBarItem.selectedImage = [[UIImage imageNamed:seleImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIView *bgView = [[UIView alloc] initWithFrame:self.tabBar.bounds];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.tabBar insertSubview:bgView atIndex:0];
    self.tabBar.opaque = YES;
    [self addChildViewController:nav];
}
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    if ([viewController.tabBarItem.image isEqual:[UIImage imageNamed:@"find_topic_openlive_btn"]]){
        LiveViewController *liveVC = [[LiveViewController alloc] init];
        liveVC.modalTransitionStyle = UIModalTransitionStylePartialCurl;
        [self presentViewController:liveVC animated:YES completion:nil];
        return NO;
    }
    return YES;
}
@end
